<template>
  <el-cascader
    size="mini"
    :options="options"
    :props="defaultProps"
    separator="-"
    :value="value"
    @change="changeValue"
  />
</template>

<script>
import { getDeparment } from '@/api/deparment'
import { transList2TreeData } from '@/utils'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      options: [],
      defaultProps: {
        label: 'name',
        value: 'id'
      }
    }
  },
  created() {
    this.getData()
  },
  methods: {
    async getData() {
      this.options = transList2TreeData(await getDeparment(), 0)
    },
    changeValue(value) {
      value.length
        ? this.$emit('input', value[value.length - 1])
        : this.$emit('input', null)
    }
  }
}
</script>

<style></style>
